<?php
namespace Rainrock\Framework\Controller;


use Rainrock\Framework\kernel\core\Controller;
use Rainrock\Framework\kernel\base\Session;
use Rainrock\Framework\kernel\base\Request;

/**
*	需要登录就继承这个控制器
*/
class AuthController extends Controller{
	
	public function checkAccess()
	{
		if($this->getAuth())return;
		if(Request::isajax())return $this->returnerror('请先登录', 199);
		if(PHP_SAPI!='cli')$this->location('?m=login');
		return 'not login';
	}
	
	public function exitAction()
	{
		$this->exitcheckAction();
		$this->location('?m=login');
	}
	
	public function exitcheckAction()
	{
		$tokenid = (int)Session::get('tokenid');
		if($tokenid > 0)$this->m('systoken')->update('`online`=0',$tokenid);
		Session::remove('tokenid');
		return $this->returnsuccess();
	}
	
	public function saveregidAction()
	{
		$tokenid 	= (int)Session::get('tokenid');
		$regid 		= Request::get('regid');
		if($tokenid && $regid){
			$this->m('systoken')->update("`regid`='$regid'",$tokenid);
		}
		return $this->returnsuccess();
	}
}